package org.jeecg.modules.qyxx.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.config.annotations.OrgPermissionAnnotation;
import org.jeecg.config.util.CurrentOrgInfoUtil;
import org.jeecg.modules.ckts.service.ICktsShjdService;
import org.jeecg.modules.ckts.vo.CktsReportDataVo;
import org.jeecg.modules.fk.service.IDjOrgService;
import org.jeecg.modules.fk.utils.CheckRoleUtil;
import org.jeecg.modules.qyxx.entity.*;
import org.jeecg.modules.qyxx.entity.qo.SjmkjgOrderQo;
import org.jeecg.modules.qyxx.entity.req.BgNsrjbxxReq;
import org.jeecg.modules.qyxx.entity.resp.BgPjmoXjVo;
import org.jeecg.modules.qyxx.service.*;
import org.jeecg.modules.qyxx.util.DateUtils;
import org.jeecg.modules.qyxxora.service.IZbjkScyszbjcMxService;
import org.jeecg.modules.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.*;

/**
 * @Description: 风险报告
 * @Author: ZJJ
 * @Date: 2021-06-01
 * @Version: V1.0
 */
@Slf4j
@Api(tags = "风险报告")
@RestController
@RequestMapping("/riskReport")
public class RiskReportController {
    @Autowired
    private IBgNsrJbxxService bgNsrJbxxService;
    @Autowired
    private IBgFpHzNdSygysService bgFpHzNdSygysService;
    @Autowired
    private IBgFpHzNdXyjxsService bgFpHzNdXyjxsService;
    @Autowired
    private IBgFpTopSygysService bgFpTopSygysService;
    @Autowired
    private IBgFpTopXyjxsService bgFpTopXyjxsService;
    @Autowired
    private IBgFpTopSyyclService bgFpTopSyyclService;
    @Autowired
    private IBgFpTopXycpService bgFpTopXycpService;
    @Autowired
    private IBgFpHzNdQtzyzcService bgFpHzNdQtzyzcService;
    @Autowired
    private IBgFpHzNdFxyjService bgFpHzNdFxyjService;
    @Autowired
    private IBgFpHzNdWdxSxygysjxsService bgFpHzNdWdxSxygysjxsService;
    @Autowired
    private IBgFpHzNdJzdSxygysjxsService bgFpHzNdJzdSxygysjxsService;
    @Autowired
    private IBgHzNdCwbbService bgHzNdCwbbService;
    @Autowired
    private ITycLsgsxxLsmcService tycLsgsxx;

    @Autowired
    private ITycQsggService tycQsggService;

    @Autowired
    private ITycXzcfService tycXzcfService;

    @Autowired
    private ITycSswfService tycSswfService;
    @Autowired
    private IBgHzNdSbService bgHzNdSbService;
    @Autowired
    private IBgMxZzssbService bgMxZzssbService;
    @Autowired
    private IBgMxQysdssbService bgMxQysdssbService;
    @Autowired
    private IBgHzNdYqsqService bgHzNdYqsqService;
    @Autowired
    private IBgMxYqsqService bgMxYqsqService;
    @Autowired
    private IBgHzFjdSbZzsqysdsService bgHzFjdSbZzsqysdsService;
    @Autowired
    private IBgHzNdQsqkService bgHzNdQsqkService;
    @Autowired
    private IBgMxQsqkService bgMxQsqkService;
    @Autowired
    private IBgHzNdBndzzsfxService bgHzNdBndzzsfxService;
    @Autowired
    private IBgHzNdBndsdsfxService bgHzNdBndsdsfxService;
    @Autowired
    private IBgSjmkjgOrderService bgSjmkjgOrderService;
    @Autowired
    private IDjOrgService djOrgService;
    @Autowired
    private IBgFpHzYfQtzyzcService bgFpHzYfQtzyzcService;
    @Autowired
    private IFkPdfService fkPdfService;
    @Autowired
    private ITycSwpjService tycSwpjService;
    @Autowired
    private IZbjkScyszbjcMxService zbjkScyszbjcMxService;
    @Autowired
    private IBgFpHzNdJzdSxyyclcpService bgFpHzNdJzdSxyyclcpService;
    @Autowired
    private IBgFpHzNdWdxSxyyclcpService bgFpHzNdWdxSxyyclcpService;
    @Autowired
    private IBgHzNdCwbbHbService bgHzNdCwbbHbService;
    @Autowired
    private IBgHzNdSbQwszService bgHzNdSbQwszService;
    @Autowired
    private IBgFpHzJdJzdSxygysjxsHbService bgFpHzJdJzdSxygysjxsHbService;
    @Autowired
    private ICktsShjdService cktsShjdService;
    @Autowired
    private ISysUserService sysUserService;

    @AutoLog(value = "报告模块数据加工状态列表")
    @PostMapping(value = "/list")
    // @OrgPermissionAnnotation
    public Result<?> list(@RequestBody SjmkjgOrderQo qo) {
       /* String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            qo.setDjxh(djxh);
        }*/
        /*List<DjOrg> djOrgs = djOrgService.listForPage(qo);
        List<BgSjmkjgOrder> bgSjmkjgOrders = bgSjmkjgOrderService.selectList(qo, djOrgs);
        Page<BgSjmkjgOrder> page = new Page<>(qo.getPageNo(), qo.getPageSize());
        PageInfo<BgSjmkjgOrder> pageInfo = new PageInfo<>(bgSjmkjgOrders);
        page.setRecords(pageInfo.getList());
        page.setCurrent(qo.getPageNo());
        page.setTotal(pageInfo.getTotal());
        page.setSize(qo.getPageSize());*/
        Page<BgSjmkjgOrder> page = getReportList(qo);
        return Result.OK(page);
    }

    public Page<BgSjmkjgOrder> getReportList(SjmkjgOrderQo qo) {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        Set<String> roleNameListString = sysUserService.getUserRolesSet(loginUser.getUsername());
        //判断是否为部门领导，若是则添加部门前缀作为查询条件
        if (CheckRoleUtil.checkIsDeptAdmin(roleNameListString)) {
            //省行，分支行，网点领导
            qo.setKeyWord(loginUser.getOrgCode());
        } else if (!CheckRoleUtil.checkIsSysAdmin(roleNameListString)) {
            //不是部门领导，也不是管理员，则只能查询管户
            qo.setManageUserId(loginUser.getId());
        }
        return bgSjmkjgOrderService.getReportList(qo);
    }

    @AutoLog(value = "获取纳税人基本信息")
    @PostMapping(value = "/nsrjbxx")
    @OrgPermissionAnnotation
    public Result<?> nsrjbxx(@RequestBody BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        BgNsrJbxx jbxx = bgNsrJbxxService.getQyxq(req.getDjxh());
        if (jbxx.getZczj() != null) {
            jbxx.setZczj(jbxx.getZczj().divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
        }
        List<TycSwpj> swpjList = tycSwpjService.swpj(req);
        if (swpjList != null && swpjList.size() > 0) {
            TycSwpj tycSwpj = swpjList.get(swpjList.size() - 1);
            if (org.apache.commons.lang3.StringUtils.isBlank(tycSwpj.getGrade()) || "无".equals(tycSwpj.getGrade())) {
                jbxx.setNsrxydj(String.format("未查询到记录（评价年份：%s年)", tycSwpj.getYear()));
            } else {
                jbxx.setNsrxydj(String.format("%s级（评价年份：%s年)", tycSwpj.getGrade(), tycSwpj.getYear()));
            }
        }
        return Result.OK(jbxx);
    }

    @AutoLog(value = "体检概况")
    @ApiOperation("体检概况")
    @PostMapping(value = "/tjgk")
    @OrgPermissionAnnotation
    public Result<?> tjgk(@RequestBody BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(zbjkScyszbjcMxService.tjgk(req));
    }

    @AutoLog(value = "评价模型详解")
    @ApiOperation("评价模型详解")
    @PostMapping(value = "/pjmxxj")
    @OrgPermissionAnnotation
    public Result<List<BgPjmoXjVo>> pjmxxj(@RequestBody BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(zbjkScyszbjcMxService.pjmxxj(req));
    }

    /*@AutoLog(value = "获取上游供应商汇总数据")
    @PostMapping(value = "/fpHzNdSygys")
    public Result<?> fpHzNdSygys(String djxh) {
        LambdaQueryWrapper<BgFpHzNdSygys> wrapper = Wrappers.lambdaQuery(BgFpHzNdSygys.class);
        wrapper.eq(BgFpHzNdSygys::getDjxh, djxh).groupBy(BgFpHzNdSygys::getTjnd);
        return Result.OK(bgFpHzNdSygysService.listMaps(wrapper));
    }

    @AutoLog(value = "获取下游经销商汇总数据")
    @PostMapping(value = "/fpHzNdXyjxs")
    public Result<?> fpHzNdXyjxs(String djxh) {
        LambdaQueryWrapper<BgFpHzNdXyjxs> wrapper = Wrappers.lambdaQuery(BgFpHzNdXyjxs.class);
        wrapper.eq(BgFpHzNdXyjxs::getDjxh, djxh).groupBy(BgFpHzNdXyjxs::getTjnd);
        return Result.OK(bgFpHzNdXyjxsService.listMaps(wrapper));
    }

    @AutoLog(value = "获取上游前10供应商数据")
    @PostMapping(value = "/fpTopSygys")
    public Result<?> fpTopSygys(String djxh) {
        return Result.OK(bgFpTopSygysService.fpTopSygys(djxh));
    }

    @AutoLog(value = "获取下游前10经销商数据")
    @PostMapping(value = "/fpTopXyjxs")
    public Result<?> fpTopXyjxs(String djxh) {
        return Result.OK(bgFpTopXyjxsService.fpTopXyjxs(djxh));
    }*/

    @AutoLog(value = "获取供应链经营分析")
    @ApiOperation("获取供应链经营分析")
    @PostMapping(value = "/fpGyljyfx")
    @OrgPermissionAnnotation
    public Result<?> fpGyljyfx(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        } else {
            djxh = req.getDjxh();
        }
        Map<String, Object> map = new HashMap<>();
        Date jssj = req.getJssj();
        DateUtils utils = DateUtils.getInstance();
        List<String> tjnds = utils.nearlyThreeYears(req.getKssj(), jssj);
        // 获取上游供应商数据汇总
        map.put("fpHzNdSygys", bgFpHzNdSygysService.sygyssjhz(djxh, tjnds, jssj));
        // 获取下游经销商数据汇总
        map.put("fpHzNdXyjxs", bgFpHzNdXyjxsService.xyjxssjhz(djxh, tjnds, jssj));
        // 上游供应商前10
        map.put("fpTopSygys", bgFpTopSygysService.fpTopSygys(djxh, tjnds, jssj));
        // 下游经销商前10
        map.put("fpTopXyjxs", bgFpTopXyjxsService.fpTopXyjxs(djxh, tjnds, jssj));
        // 上游原材料前10
        map.put("fpTopSyycl", bgFpTopSyyclService.fpTopSyycl(djxh, tjnds, jssj));
        // 下游原材料前10
        map.put("fpTopXycp", bgFpTopXycpService.fpTopXycp(djxh, tjnds, jssj));
        map.put("fpHzNdQtzyzc", bgFpHzNdQtzyzcService.fpHzNdQtzyzc(djxh, tjnds, jssj));
        map.put("fpHzNdFxyj", bgFpHzNdFxyjService.fpHzNdFxyj(djxh, tjnds));
        // 年月的水费支出
        map.put("fpHzYfSfzc", bgFpHzYfQtzyzcService.fpHzYfSfzc(djxh, tjnds));
        // 年月的电费支出
        map.put("fpHzYfDfzc", bgFpHzYfQtzyzcService.fpHzYfDfzc(djxh, tjnds));
        // 年月的燃气支出
        map.put("fpHzYfRqzc", bgFpHzYfQtzyzcService.fpHzYfRqzc(djxh, tjnds));
        // 年月的运输及仓储支出
        map.put("fpHzYfYszc", bgFpHzYfQtzyzcService.fpHzYfYszc(djxh, tjnds));
        map.put("fpHzYfRlzc", bgFpHzYfQtzyzcService.fpHzYfRlzc(djxh, tjnds));
        map.put("fpHzNdWdxSxygysjxs", bgFpHzNdWdxSxygysjxsService.fpHzNdWdxSxygysjxs(djxh, tjnds, jssj));
        map.put("fpHzNdJzdSxygysjxs", bgFpHzNdJzdSxygysjxsService.fpHzNdJzdSxygysjxs(djxh, tjnds, jssj));
        return Result.OK(map);
    }

    @AutoLog(value = "上下游发票数据分析图表")
    @PostMapping(value = "/getSxyFpSjFx")
    @OrgPermissionAnnotation
    public Result<?> getSxyFpSjFx(@RequestBody BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(bgFpHzJdJzdSxygysjxsHbService.getSxyFpSjFx(req));
    }

    @AutoLog(value = "近三年企业营收和利润分析")
    @PostMapping(value = "/qyYsAndLrFx")
    @OrgPermissionAnnotation
    public Result<?> qyYsAndLrFx(@RequestBody BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(bgHzNdCwbbHbService.qyYsAndLrFx(req));
    }

    /*@AutoLog(value = "近三年利润分析")
    @PostMapping(value = "/qyLrFx")
    public Result<?> qyLrFx(BgNsrjbxxReq req) {
        return Result.OK(bgHzNdCwbbHbService.qyLrFx(req));
    }*/

    /*@AutoLog(value = "获取上游前5原材料数据")
    @PostMapping(value = "/fpTopSyycl")
    public Result<?> fpTopSyycl(String djxh) {
        return Result.OK(bgFpTopSyyclService.fpTopSyycl(djxh));
    }

    @AutoLog(value = "获取上游前5原材料数据")
    @PostMapping(value = "/fpTopXycp")
    public Result<?> fpTopXycp(String djxh) {
        return Result.OK(bgFpTopXycpService.fpTopXycp(djxh));
    }

    @AutoLog(value = "获取其他重要支出年汇总数据")
    @PostMapping(value = "/fpHzNdQtzyzc")
    public Result<?> fpHzNdQtzyzc(String djxh) {
        return Result.OK(bgFpHzNdQtzyzcService.fpHzNdQtzyzc(djxh));
    }

    @AutoLog(value = "获取发票风险预警汇总数据")
    @PostMapping(value = "/fpHzNdFxyj")
    public Result<?> fpHzNdFxyj(String djxh) {
        return Result.OK(bgFpHzNdFxyjService.fpHzNdFxyj(djxh));
    }

    @AutoLog(value = "获取上下游供应商和经销商稳定性汇总数据")
    @PostMapping(value = "/fpHzNdWdxSxygysjxs")
    public Result<?> fpHzNdWdxSxygysjxs(String djxh) {
        return Result.OK(bgFpHzNdWdxSxygysjxsService.fpHzNdWdxSxygysjxs(djxh));
    }

    @AutoLog(value = "获取上下游供应商和经销商集中度汇总数据")
    @PostMapping(value = "/fpHzNdJzdSxygysjxs")
    public Result<?> fpHzNdJzdSxygysjxs(String djxh) {
        return Result.OK(bgFpHzNdJzdSxygysjxsService.fpHzNdJzdSxygysjxs(djxh));
    }*/

    @ApiOperation("获取财务指标分析汇总数据")
    @AutoLog(value = "获取财务指标分析汇总数据")
    @PostMapping(value = "/hzNdCwbb")
    @OrgPermissionAnnotation
    public Result<?> hzNdCwbb(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(bgHzNdCwbbService.hzNdCwbb(req));
    }

    @ApiOperation("获取申报汇总数据")
    @AutoLog(value = "获取申报汇总数据")
    @PostMapping(value = "/hzNdSb")
    @OrgPermissionAnnotation
    public Result<?> hzNdSb(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(bgHzNdSbService.hzNdSb(req));
    }

    @AutoLog(value = "获取增值税申报明细数据")
    @PostMapping(value = "/mxZzssb")
    @OrgPermissionAnnotation
    public Result<?> mxZzssb(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(bgMxZzssbService.mxZzssb(req));
    }

    @AutoLog(value = "获取企业所得税申报明细数据")
    @PostMapping(value = "/mxQysdssb")
    @OrgPermissionAnnotation
    public Result<?> mxQysdssb(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(bgMxQysdssbService.mxZzssb(req));
    }

    @AutoLog(value = "获取逾期申报汇总数据")
    @PostMapping(value = "/hzNdYqsq")
    @OrgPermissionAnnotation
    public Result<?> hzNdYqsq(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(bgHzNdYqsqService.hzNdYqsq(req));
    }

    @AutoLog(value = "获取逾期申报明细数据")
    @PostMapping(value = "/mxYqsq")
    @OrgPermissionAnnotation
    public Result<?> mxYqsq(String djxh, String zsxm, String tjnd) {
        String shxydm = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(shxydm)) {
            djxh = shxydm;
        }
        return Result.OK(bgMxYqsqService.mxYqsq(djxh, zsxm, tjnd));
    }

    @ApiOperation("获取欠税情况汇总数据")
    @AutoLog(value = "获取欠税情况汇总数据")
    @PostMapping(value = "/hzNdQsqk")
    @OrgPermissionAnnotation
    public Result<?> hzNdQsqk(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(bgHzNdQsqkService.hzNdQsqk(req));
    }

    @ApiOperation("获取欠税情况明细数据")
    @AutoLog(value = "获取欠税情况明细数据")
    @PostMapping(value = "/mxQsqk")
    @OrgPermissionAnnotation
    public Result<?> mxQsqk(String djxh, String zsxm, String tjnd) {
        String shxydm = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(shxydm)) {
            djxh = shxydm;
        }
        return Result.OK(bgMxQsqkService.mxQsqk(djxh, zsxm, tjnd));
    }

    @AutoLog(value = "获取本年度增值税分析")
    @PostMapping(value = "/hzNdBndzzsfx")
    @OrgPermissionAnnotation
    public Result<?> hzNdBndzzsfx(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(bgHzNdBndzzsfxService.hzNdBndzzsfx(req));
    }

    @AutoLog(value = "获取本年度所得税分析")
    @PostMapping(value = "/hzNdBndsdsfx")
    @OrgPermissionAnnotation
    public Result<?> hzNdBndsdsfx(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(bgHzNdBndsdsfxService.hzNdBndsdsfx(req));
    }


    @ApiOperation("获取税务评级")
    @AutoLog(value = "获取税务评级")
    @PostMapping(value = "/swpj")
    @OrgPermissionAnnotation
    public Result<List<TycSwpj>> swpj(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(tycSwpjService.swpj(req));
    }

    @AutoLog(value = "前五名原材料产品稳定性指标")
    @PostMapping(value = "/getTop5YclCpWdxZb")
    @OrgPermissionAnnotation
    public Result<?> getTop5YclCpWdxZb(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(bgFpHzNdWdxSxyyclcpService.getTop5YclCpWdxZb(req));
    }

    @AutoLog(value = "前五名原材料产品集中度指标")
    @PostMapping(value = "/getTop5YclCpJzdZb")
    @OrgPermissionAnnotation
    public Result<?> getTop5YclCpJzdZb(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(bgFpHzNdJzdSxyyclcpService.getTop5YclCpJzdZb(req));
    }


    @AutoLog(value = "前五大税种分析")
    @PostMapping(value = "/getTop5SzFx")
    @OrgPermissionAnnotation
    public Result<?> getTop5SzFx(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(bgHzNdSbQwszService.getTop5SzFx(req));
    }


    @AutoLog(value = "各季度营业收入明细")
    @PostMapping(value = "/getGjdYysrMx")
    @OrgPermissionAnnotation
    public Result<?> getGjdYysrMx(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(bgHzNdCwbbHbService.getGjdYysrMx(req));
    }

    @AutoLog(value = "增值税跟企业所得税分季度汇总趋势表")
    @PostMapping(value = "/zzsAndQysdsHz")
    @OrgPermissionAnnotation
    public Result<?> zzsAndQysdsHz(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(bgHzFjdSbZzsqysdsService.zzsAndQysdsHz(req));
    }


    @ApiOperation("企业基本信息变更")
    @AutoLog(value = "企业基本信息变更")
    @PostMapping(value = "/qyjbxxBg")
    @OrgPermissionAnnotation
    public Result<?> qyjbxxBg(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(tycLsgsxx.qyjbxxBg(req));
    }

    @ApiOperation("欠税公告")
    @AutoLog(value = "欠税公告")
    @PostMapping(value = "/qsggBg")
    @OrgPermissionAnnotation
    public Result<List<TycQsgg>> qsggBg(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(tycQsggService.qsggBg(req));
    }

    @ApiOperation("行政处罚")
    @AutoLog(value = "行政处罚")
    @PostMapping(value = "/xzcfBg")
    @OrgPermissionAnnotation
    // public Result<Page<TycXzcf>> xzcf(@RequestBody SsjcSssjDTO req) {
    public Result<List<TycXzcf>> xzcfBg(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(tycXzcfService.xzcfBg(req));
    }

    @ApiOperation("税收违法")
    @AutoLog(value = "税收违法")
    @PostMapping(value = "/sswfBg")
    @OrgPermissionAnnotation
    //public Result<Page<TycSswf>> sswf(@RequestBody SsjcSssjDTO req) {
    public Result<List<TycSswf>> sswfBg(BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        return Result.OK(tycSswfService.sswfBg(req));
    }

    @ApiOperation("出口退税数据")
    @PostMapping(value = "/getCktsData")
    @OrgPermissionAnnotation
    public Result<List<CktsReportDataVo>> getCktsData(@Validated @RequestBody BgNsrjbxxReq req) {
        Date jssj = req.getJssj();
        Calendar kssjCal = Calendar.getInstance();
        kssjCal.setTime(jssj);
        kssjCal.add(Calendar.YEAR, -1);
        kssjCal.set(Calendar.MONTH, 0);
        kssjCal.set(Calendar.DATE, 1);
        DateUtils dateUtils = DateUtils.getInstance();
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        return Result.OK(cktsShjdService.selectCktsReportData(djxh, dateUtils.DatetoStr(kssjCal.getTime(), "yyyy-MM"), dateUtils.DatetoStr(jssj, "yyyy-MM")));
    }

    @AutoLog(value = "导出PDF")
    @PostMapping(value = "/exportPDF")
    @OrgPermissionAnnotation
    public Result<?> exportPDF(@RequestBody BgNsrjbxxReq req) {
        String djxh = CurrentOrgInfoUtil.getCurrentOrgShxydm();
        if (StringUtil.isNotBlank(djxh)) {
            req.setDjxh(djxh);
        }
        // HtmlToPdf.convert("http://10.10.18.244:3000/dhcsfxbg", "d:/data/pdf/wkhtmltopdf10.pdf");
        String flag = fkPdfService.getReportPdf(req);
        if (StringUtils.hasLength(flag)) {
            return Result.OK(flag);
        } else {
            return Result.error("导出PDF失败");
        }
    }
}
